﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

using Weazel.Badger.Vhdl.Types;
using Weazel.Badger.Vhdl.Operators.Unary;

namespace Weazel.Badger.Vhdl.Expressions
{
  public class ConversionExpression : UnaryExpression
  {
    public override TypeSet GetPossibleTypes()
    {
      Expression.GetPossibleTypes();
      return new TypeSet (target);
    }

		public override void SetActualType(Entity entity, Process process, Statements.StatementCollection statements, Vhdl.Types.Type type)
    {
			Expression.SetActualType(entity, process, statements, from);

      this.Type = target;
    }

    private Vhdl.Types.Type target;
    private Vhdl.Types.Type from;

    public ConversionExpression(
			IComponent parentContainer, 
			Expression child, 
			Vhdl.Types.Type from, 
			Vhdl.Types.Type target
		) 
			: base(parentContainer, child, target, null)
    {
      this.target = target;
      this.from = from;

      if (target.TypeId == Types.Types.Character)
      {
        Operator = new CharacterConversion();
        this.Type = new Vhdl.Types.Boolean();
      }
      else if (target.TypeId == Types.Types.Boolean)
      {
        throw new NotImplementedException();
      }
      else if (target.TypeId == Types.Types.Signed)
      {
	
					Operator = new SignedConversion(target.Width, from);
					this.Type = new Signed(target.Width);
				
      }
      else if (target.TypeId == Types.Types.Unsigned)
      {
        Operator = new UnsignedConversion(target.Width, from);
        this.Type = new Unsigned(target.Width);
      }
      else if (target.TypeId == Types.Types.Integer)
      {
        Operator = new IntegerConversion();
        this.Type = new Integer(target.Width);
      }
      else if (target.TypeId == Types.Types.StdLogic)
      {
        throw new NotImplementedException();
      }
      else if (target.TypeId == Types.Types.StdLogicVector)
      {
        Operator = new StdLogicVectorConversion(target.Width, from);
        this.Type = new StdLogicVector(target.Width);
      }
      else
      {
        throw new NotSupportedException();
      }

   }
  }
}
